#ifndef TRACTASKLISTSERVICECLIENT_H
#define TRACTASKLISTSERVICECLIENT_H

#include <QObject>
#include <QtNetwork>
#include "error.h"
#include "qfutureinterface.h"

#include "../tasktop4qtcreator/tasklistroot.h"
#include "../tasktop4qtcreator/taskimage.h"
#include "../tasktop4qtcreator/taskcontainer.h"
#include "../tasktop4qtcreator/eventscontainer.h"
#include "../tasktop4qtcreator/tasklistserviceclient.h"
#include "tracticketexplorerbackend.h"


class TracTaskListServiceClient : public TaskListServiceClient
{
    Q_OBJECT
public:
    explicit TracTaskListServiceClient(QObject *parent = 0);
    ~TracTaskListServiceClient();

signals:
    void onRootRetrieved(TaskListRoot *root);
    void onVersionRetrieved(QString version);
    void onCallFailed(Error *error);
    void onImageRetrieved(TaskImage *image);
    void onContainerRetrieved(TaskContainer *container);
    void onEventsRetrieved(EventsContainer *events);
    void onTaskRetrieved(TaskHandle *task);

public slots:
    void root();
    void version();
    void container(QString identifier);
    void image(QString identifier);
    void getEvents(qlonglong timestamp);
    void task(QString identifier);
    void syncRoot();
    void syncContainer(QString identifier);
    void syncTask(QString identifier);
    void markTaskRead(TaskHandle *task);
    void markTaskUnread(TaskHandle *task);
    void deleteTask(TaskHandle *task);
    void markContainerRead(TaskContainer *container);
    void deleteContainer(TaskContainer *container);
    void updateRepositoryConfiguration(QString containerHandle);
    void onJobChanged(QString identifier);
    void activeTask();
    void deactivateTasks();
    void activateTask(QString identifier);
    void timeoutWaitForJob();

private slots:
    void onRequestFinished(QNetworkReply *reply);
    bool sendRequest(QString urlPostfix, bool post = false);

private:
    TracTicketExplorerBackend *manager;
    QList<QString> requestedImages;
    bool requestingRoot;
    QList<QString> requestedContainers;
    QMap<QString, QFutureInterface<void>*> jobs;

};

#endif // TRACTASKLISTSERVICECLIENT_H
